//
//  TMGMineHeaderView.m
//  TMGold
//
//  Created by Mac on 2017/12/8.
//  Copyright © 2017年 tangmu. All rights reserved.
//

#import "TMGMineHeaderView.h"
#import "TMMenuControl.h"
@interface TMGMineHeaderView()
@property(nonatomic, strong) STButton                     *eyeButton;
@property(nonatomic, strong) STLabel                     *moneyLable;
@property(nonatomic, strong) STLabel                     *yesterdayLable;

@property(nonatomic, strong) TMMenuControl                     *huangjinControl;
@property(nonatomic, strong) TMMenuControl                     *touziControl;
@property(nonatomic, strong) TMMenuControl                     *yueControl;
@end
@implementation TMGMineHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}

#pragma mark --subView
- (void)configSubView{
    self.backgroundColor = [UIColor whiteColor];
    
    UIImageView * bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 193)];
    bannerImageView.image = [UIImage imageNamed:@"wdebanner"];
    bannerImageView.userInteractionEnabled = YES;
    [self addSubview:bannerImageView];
    __weak typeof(self) weakSelf =  self;
    self.eyeButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 200, 44)
                                               title:@"资产总价值（元）"
                                          titleColor:[UIColor whiteColor]
                                           titleFont:14
                                        cornerRadius:0
                                     backgroundColor:nil
                                     backgroundImage:nil
                                               image:[UIImage imageNamed:@"眼睛"]];
    [self.eyeButton setImage:[UIImage imageNamed:@"闭眼"] forState:UIControlStateSelected];
    self.eyeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.eyeButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedEyeButton];
    }];
    self.eyeButton.centerX = UIScreenWidth /2;
    [self.eyeButton makeImageRight];
    [self addSubview:self.eyeButton];
    
    self.moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(0, self.eyeButton.bottom, UIScreenWidth, 40)
                                                text:@"--：--"
                                           textColor:[UIColor whiteColor]
                                                font:32
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentCenter];
    [self addSubview:self.moneyLable];
    
    
    self.huangjinControl = [[TMMenuControl alloc] initWithFrame:CGRectMake(0, bannerImageView.bottom, UIScreenWidth / 2, 60) value:@"-:--" name:@"黄金资产" showLine:YES];
    [self.huangjinControl addTarget:self action:@selector(onSlectedControl:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.huangjinControl];
    
    //隐藏投资计划
    self.touziControl = [[TMMenuControl alloc] initWithFrame:CGRectMake(self.huangjinControl.right, bannerImageView.bottom, UIScreenWidth / 3, 60) value:@"--:--" name:@"投资计划" showLine:YES];
    [self.touziControl addTarget:self action:@selector(onSlectedControl:) forControlEvents:UIControlEventTouchUpInside];
   // [self addSubview:self.touziControl];
    
    self.yueControl = [[TMMenuControl alloc] initWithFrame:CGRectMake(self.huangjinControl.right, bannerImageView.bottom, UIScreenWidth / 2, 60) value:@"--:--" name:@"账户余额" showLine:NO];
    [self.yueControl addTarget:self action:@selector(onSlectedControl:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.yueControl];
    
    UIView * grawView = [[UIView alloc] initWithFrame:CGRectMake(0, self.yueControl.bottom, UIScreenWidth, 10)];
    grawView.backgroundColor = TM_backgroundColor;
    [self addSubview:grawView];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, grawView.bottom, UIScreenWidth, 100)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:whiteView];
    
    UIView * yeallowView = [[UIView alloc] initWithFrame:CGRectMake(20,0 +10 , 4, 15 )];
    yeallowView.backgroundColor = TM_orangeColor;
    [whiteView addSubview:yeallowView];
    
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(yeallowView.right + 15, yeallowView.top, 200, 15)
                                                     text:@"昨日收益(元)"
                                                textColor:TM_firstTextColor
                                                     font:13
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [whiteView addSubview:titleLable];
    
    STButton * lookButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 300, 30)
                                                      title:@"查看收益明细 >"
                                                 titleColor:TM_secendTextColor
                                                  titleFont:13
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:nil];
    lookButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    lookButton.right = UIScreenWidth - 20;
    lookButton.centerY = titleLable.centerY;
    [lookButton setClicAction:^(UIButton *sender) {
        [weakSelf onSlectedYesterDayButton];
    }];
    [whiteView addSubview:lookButton];
    
    self.yesterdayLable = [[STLabel alloc] initWithFrame:CGRectMake(10, titleLable.bottom + 10, UIScreenWidth - 20, 40)
                                                    text:@"--:--"
                                               textColor:TM_redColor
                                                    font:32
                                             isSizetoFit:NO
                                           textAlignment:NSTextAlignmentCenter];
    whiteView.height = self.yesterdayLable.bottom + 15;
    self.height = whiteView.bottom;
    //隐藏昨日收益
    [whiteView removeFromSuperview];
    self.height = grawView.bottom;
    
    [whiteView addSubview:self.yesterdayLable];
    
    
    //头部橘色
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, -self.height, UIScreenWidth, 2 * self.height)];
    header.backgroundColor = TM_orangeColor;
    [self insertSubview:header atIndex:0];
}
#pragma mark --Action Method
- (void)onSlectedEyeButton{
    self.eyeButton.selected = !self.eyeButton.selected;
    if (!self.eyeButton.selected) {
        self.model = self.model;
    }else{
        self.yesterdayLable.text = @"*****";
        self.moneyLable.text = @"*****";
        self.yueControl.valueLable.text = @"*****";
        self.huangjinControl.valueLable.text = @"*****";
        self.touziControl.valueLable.text = @"*****";
    }
}
- (void)onSlectedYesterDayButton{
    if (self.delegate && [self.delegate  respondsToSelector:@selector(headerViewOnSlectedMenuButton:)]) {
        [self.delegate headerViewOnSlectedMenuButton:@"查看收益明细"];
    }
}
- (void)onSlectedControl:(TMMenuControl*)sender{
    
    if (self.delegate && [self.delegate  respondsToSelector:@selector(headerViewOnSlectedMenuButton:)]) {
        [self.delegate headerViewOnSlectedMenuButton:sender.nameLable.text];
    }
}
- (void)setModel:(TMGMineHomeModel *)model{
    _model = model;
   // CGFloat allMOney = model.money.floatValue + model.invest.floatValue + model.gold.floatValue * 260;
    self.moneyLable.text = [NSString stringWithFormat:@"%@",model.total_money];
//    [TMUtils fetchCurrentGoldPrice:^(TMCurrentColdModel *currentModel) {
//        CGFloat nowallMOney = model.money.floatValue + model.invest.floatValue + model.gold.floatValue * currentModel.openpri.floatValue;
//        self.moneyLable.text = [NSString stringWithFormat:@"%0.2f",nowallMOney];
//    }];
    self.yesterdayLable.text =[NSString stringWithFormat:@"%@", model.yesterday_money];
    
    
    self.huangjinControl.valueLable.text = [NSString stringWithFormat:@"%@克" ,model.gold];
    self.huangjinControl.valueLable.attributedText = [self.huangjinControl.valueLable.text  st_convertAttributeStringWithKeyWord:@"克" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}];
    
    self.touziControl.valueLable.text = model.invest;
    self.touziControl.valueLable.attributedText = [self.touziControl.valueLable.text  st_convertAttributeStringWithKeyWord:@"克" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}];
    
    self.yueControl.valueLable.text = [NSString stringWithFormat:@"%@元",
                                       model.money];
    self.yueControl.valueLable.attributedText = [self.yueControl.valueLable.text  st_convertAttributeStringWithKeyWord:@"元" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]}];
}
@end

